package servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.Member;
import bean.MemberAdm;

@SuppressWarnings("serial")
public class IndexServlet extends HttpServlet {
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.getRequestDispatcher("./index.jsp").forward(req, resp);
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		MemberAdm memAdm = new MemberAdm();
		Member saveMem = memAdm.logIn(req.getParameter("memID"),
				req.getParameter("memPSW"));

		if (null == saveMem) {
			resp.sendRedirect("./index");
		} else {
			HttpSession session = req.getSession();
			session.setAttribute("userID", saveMem.getUserID());
			session.setAttribute("id", saveMem.getKey().getId());
			session.setAttribute("state", saveMem.isState());
			session.setAttribute("phone", saveMem.getPhone().getNumber());
			session.setAttribute("mail", saveMem.getEmail().getEmail());
			session.setAttribute("name", saveMem.getName());
			session.setAttribute("address", saveMem.getAddress());
			session.setAttribute("coMem", saveMem.isCostcoMem());

			resp.sendRedirect("./index");
		}
	}
}
